home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / networking / amitcp / lpr.lha / lpr < prev   
Encoding:
Text File  |  1994-10-31  |  3.1 KB  |  98 lines

  1. /*******************************************************************************************************************
  2. * lpr hostname printername file
  3. * currently only supports sending files to a printer daemon
  4. *
  5. * \1 restart remote printer    \1printer\n
  6. * \2 send files to queue        \2printer\n        \3size file is datafile \2size file is controlfile \1 reset
  7. * \3 list queue            \3printer\n         number of requests or users then read from tcp connection
  8. * \4 list queue
  9. * \5 remove job from queue                only local
  10. *******************************************************************************************************************/
  11.  
  12. /************************/
  13. /**CHANGE          HERE**/
  14. /************************/
  15. myhostname = 'zaturn'
  16. username = 'utzinger'
  17. /************************/
  18.  
  19. options failat 10
  20.  
  21. signal on halt
  22. signal on ioerr
  23. signal on break_c
  24.  
  25. if arg() < 1 | arg(1) = '?' then call usage 
  26.  
  27. parse arg Hostname PrI InFiles
  28. parse var InFiles file InFiles
  29.  
  30. say 'Printing file ' || file || ' on ' || Hostname || ' printer ' || PrI
  31.  
  32. /* Open printer tcp connection  and file to send */
  33.  
  34. If ~Open(pr, 'TCP:' || Hostname || '/printer', 'W') Then Do; Say '*** Service not present'; Exit 10; End
  35. If ~Open(fl, file, 'R') Then                             Do; Say '*** Cannot open file';    Exit 10; End
  36.  
  37. /* Init remote printer daemon to accept files */
  38.  
  39. writeln(pr,d2c(2) || PrI)
  40. chr=readch(pr,1)
  41. if chr ~= d2c(0) then Do; Say '*** Unknown remote printer or no authentification: ' || c2b(chr);    Exit 10; End
  42.  
  43. /* produce authentic part of file name */
  44. num=right(time(s),3)
  45.  
  46. /* send data file */
  47.  
  48. size=seek(fl,0,'END') 
  49. say 'Size Data: ' || size || ' bytes'
  50. nr = seek(fl,0,'BEGIN')
  51. writeln(pr,d2c(3) || size || ' dfA' || num || myhostname)
  52. chr=readch(pr,1)
  53. if  chr ~= d2c(0) then Do; Say '*** Not enough space to print data file on remote host: ' || c2b(chr) ;    Exit 10; End
  54. thisline=readch(fl,65535)
  55. do until eof(fl)
  56.  call writech(pr,thisline)
  57.  thisline=readch(fl,65535)
  58. end 
  59. writech(pr,d2c(0))
  60. chr=readch(pr,1)
  61. if chr ~= d2c(0) then Do; Say '*** Remote host did not receive the data file correctly: ' || c2b(chr);    Exit 10; End
  62.  
  63. /* send control file */
  64.  
  65. csize=2*length(file) + 68
  66. say 'Size Control: ' || csize || 'bytes'
  67. writeln(pr,d2c(2) || csize || ' cfA' || num || myhostname)
  68. chr=readch(pr,1)
  69. if chr ~= d2c(0) then Do; Say '*** Not enough space to print control file on remote host: ' || c2b(chr);    Exit 10; End
  70. writeln(pr,'H' || myhostname)
  71. writeln(pr,'P' || username)
  72. writeln(pr,'J' || file)
  73. writeln(pr,'C' || myhostname)
  74. writeln(pr,'L' || username)
  75. writeln(pr,'fdfA' || num || myhostname)
  76. writeln(pr,'UdfA' || num || myhostname)
  77. writeln(pr,'N' || file)
  78. writech(pr,d2c(0))
  79. chr=readch(pr,1)
  80. if chr ~= d2c(0) then Do; Say '*** Remote host did not receive the control file correctly: ' || c2b(chr);    Exit 10; End
  81.  
  82. call close fl; call close pr
  83. say 'File printed'
  84. exit 0
  85.  
  86. /* ----------------------------------------------------------------------- */
  87. /* Error Handling */
  88. halt:
  89. oerr:
  90. reak_c:
  91. exit 10
  92.  
  93. /* ----------------------------------------------------------------------- */
  94. usage:
  95.     say "Usage: lpr hostname printername filename"
  96.     say
  97.     exit 0
  98.